﻿
namespace Northwind.ViewModel
{
    using GalaSoft.MvvmLight.Command;
    using Northwind.ViewModel.Enumerations;
    using Northwind.Interfaces.Data.Model;
    using Northwind.Application;
    using Northwind.Application.Model;
    using Northwind.Data;

    public class OrderWizardOrderDetailsViewModel : OrderViewModel
    {
        #region IOrderWizardChildViewModel

        WizardChildFlow _showSibling;
        public WizardChildFlow ShowSibling
        {
            get
            {
                return _showSibling;
            }
            set
            {
                _showSibling = value;
                RaisePropertyChanged("ShowSibling");
                
            }
        }

        RelayCommand _showNextWizardChild;
        public RelayCommand ShowNextWizardChild
        {
            get
            {
                if (_showNextWizardChild == null)
                {
                    _showNextWizardChild = new RelayCommand(
                        () => { ShowSibling = WizardChildFlow.ShowNextChild; },
                        () => true);
                }
                return _showNextWizardChild;
            }
        }

        RelayCommand _showPreviousWizardChild;
        public RelayCommand ShowPreviousWizardChild
        {
            get
            {
                if (_showPreviousWizardChild == null)
                {
                    _showPreviousWizardChild = new RelayCommand(
                        () => { ShowSibling = WizardChildFlow.ShowPreviousChild; },
                        () => true);
                }

                return _showPreviousWizardChild;

            }
        }

        #endregion

        #region Constructor

        //IOrderModel order;

        public OrderWizardOrderDetailsViewModel():
            base(new OrderModel(new Order()))
        {
            Initialize();
        }

        #endregion

        #region Private Methods
        
        private void Initialize()
        {
            TempOrderDetail = new OrderItemViewModel(this);
        }

        #endregion

        #region Public Properties

        OrderItemViewModel _tempOrderDetail;
        public OrderItemViewModel TempOrderDetail
        {
            get
            {
                return _tempOrderDetail;
            }
            private set
            {
                _tempOrderDetail = value;
                RaisePropertyChanged("TempOrderDetail");
            }
        }

        #endregion

        #region Commands

        RelayCommand _addOrderDetail;
        public RelayCommand AddOrderDetail
        {
            get
            {
                if (_addOrderDetail == null)
                {
                    _addOrderDetail = new RelayCommand(
                        () =>
                        {
                            this.TempOrderDetail.Product = this.TempOrderDetail.SelectedProduct;
                            this.OrderDetails.Add(this.TempOrderDetail);                            
                            this.TempOrderDetail = new OrderItemViewModel(this);
                        }
                        );
                }

                return _addOrderDetail;
            }
        
        }
        #endregion
    }
}
